description "Datadog Security Agent"

start on started datadog-agent
stop on (runlevel [!2345] or stopping datadog-agent)

respawn
respawn limit 10 5
normal exit 0

# Logging to console from the agent is disabled since the agent already logs using file or
# syslog depending on its configuration. We make upstart log what the process still outputs in order
# to log panics/crashes to /var/log/upstart/datadog-agent.log
console log
env DD_LOG_TO_CONSOLE=false

pre-start script
  # Do not run if security-agent.yaml does not exist
  test -f <%= etc_dir %>/security-agent.yaml || { stop ; exit 0; }
end script

script
  exec <%= install_dir %>/embedded/bin/security-agent start -c <%= etc_dir %>/datadog.yaml -c <%= etc_dir %>/security-agent.yaml -p <%= install_dir %>/run/security-agent.pid
end script

post-stop script
  rm -f <%= install_dir %>/run/security-agent.pid
end script
